<?php

namespace Database\Factories;

use App\Models\User\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
 */
class UserFactory extends Factory
{
    protected $model = User::class;
    /**
     * The current password being used by the factory.
     */
    protected static ?string $password;


    protected function withFaker()
    {
        return fake('zh_CN');
    }

    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        $faker = $this->faker;
        return [
            'username' => $faker->unique()->userName,
            'email' => $faker->unique()->safeEmail(),
            'avatar' => $faker->image,
            'gender' => $faker->randomElement([0,1,-1]),
            'nation_code' => "86",
            'mobile_phone' => $faker->phoneNumber(),
            'password' => static::$password ??= Hash::make('password'),
            'state' => 1,
            'last_login_ip'=> ip2long($faker->ipv4),
            'last_login_at' => $faker->dateTime,
            'registered_at' => $faker->dateTime,
            'created_at' => $faker->dateTime,
            'updated_at' => $faker->dateTime,
        ];
    }
}
